<?php

namespace backend\controllers;

use backend\utils\AppUtil;
use backend\utils\FileUpUtil;
use backend\utils\Jwt;
use common\extensions\pinyin\PinYin;
use common\extensions\rsa\Rsa;
use Yii;

class OtherController extends BaseController
{
    /**
     * @desc 拼音
     * @return void
     * @Date: 2024/11/4
     */
    public function actionPinyin()
    {
        echo PinYin::convert('我爱北京天安门');
        exit;
    }

    /**
     * @desc rsa
     * @return void
     * @Date: 2024/11/4
     */
    public function actionRsa()
    {
        $str1 = Rsa::encrypt('123456');
        echo Rsa::decrypt($str1);
        exit;
    }


    /**
     * @desc jwt
     * @return void
     * @Date: 2024/11/5
     */
    public function actionJwt()
    {
        $arr = [
            'uuid' => AppUtil::init_uuid(),
            'username' => 'username123',
            'real_name' => 'real_name123',
            'tel' => 'tel123',
            'school_id' => 'school_id123',
            'school_name' => 'school_name123',
            'school_code' => 'school_code123',
            'roles' => '',
            'iss' => 'dataCenter',
            'iat' => time(),  //签发时间
            'exp' => time() + 3600,  //过期时间秒
            'nbf' => time() + 0,  //该时间之前不接收处理该Token
            'sub' => 'www.admin.com',  //面向的用户
            'jti' => md5(uniqid('JWT') . time())  //该Token唯一标识
        ];
        $access_token = Jwt::getToken($arr);
        $token_arr = Jwt::verifyToken($access_token);
        print_r($token_arr);
        exit;
    }

    /**
     * @desc touch file
     * @return void
     * @Date: 2024/11/5
     */
    public function actionTouch()
    {
        $dir = AppUtil::get_web_path();
        $dt = date('Ymd');
        FileUpUtil::touch_file("{$dir}/files/up_file/{$dt}/11223344.5566.docx");
        exit;
    }

}
